<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <script>
    function red() {
      console.log(red);
    }
    function green() {
      console.log(green);
    }
    function yellow() {
      console.log(yellow);
    }

    function light(timer, cb) {
      return new Promise((resolve) => {
        cb();
        setTimeout(() => {
          resolve();
        }, timer);
      });
    }

    function setup() {
      Promise.resolve()
        .then(() => {
          return light(3000, red);
        })
        .then(() => {
          return light(2000, green);
        })
        .then(() => {
          return light(1000, yellow);
        })
        .then(() => {
          return setup();
        });
    }
    setup();


    
  </script>
  <body></body>
</html>
